#include <forward_list>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;

int splice1()
{
	forward_list<int> l1 = { 1, 2, 3, 4, 5 };
	forward_list<int> l2 = { 97, 98, 99 };

	// find iterator before 3 in l1
	auto pos1 = l1.before_begin();
	for (auto pb1 = l1.begin(); pb1 != l1.end(); ++pb1, ++pos1)
	{
		if (*pb1 == 3)
		{
			break;	// found
		}
	}

	// find iterator before 99 in l2
	auto pos2 = l2.before_begin();
	for (; next(pos2) != l2.end(); ++pos2)
	{
		if (*next(pos2) == 99)
		{
			break;	// found
		}
	}

	// splice 99 from l2 to l1 before 3
	l1.splice_after(pos1, l2, pos2);
	copy(l1.cbegin(), l1.cend(), ostream_iterator<int>(cout, " "));
	cout << endl;
	copy(l2.cbegin(), l2.cend(), ostream_iterator<int>(cout, " "));
	cout << endl;

	return 0;
}